// CLIENT SIDE

// Sets the fucking points... piece of shit
function TDMGETPOINTS2(data)
	local PlayerPointsByXP = data:ReadString()
	local PlayerPointsByXPID = data:ReadString()
	if player.GetByID(PlayerPointsByXPID):IsValid() then
	player.GetByID(PlayerPointsByXPID):SetPData("MyXPPoints", PlayerPointsByXP)
	end
end
usermessage.Hook("TDMGETPOINTS2", TDMGETPOINTS2)


function TimeLimitUnOfficialMenu(data)
	local TimeScoreThing = data:ReadString()
	local PlayerID = data:ReadString()
	if player.GetByID(PlayerID):IsValid() then
	player.GetByID(PlayerID):SetPData("MyTimerLimiter", TimeScoreThing)
	end
end
usermessage.Hook("TimeLimitUnOfficialMenu", TimeLimitUnOfficialMenu)

// Sets the score menu thing
function PlaceScoreForMenu(data)
	local GetPlayerID = data:ReadShort()
	local GetTotalScore = data:ReadShort()
	if player.GetByID(GetPlayerID):IsValid() then
	player.GetByID(GetPlayerID):SetPData("TDM_Total_Score_Ok", GetTotalScore)
	end
end
usermessage.Hook("PlaceScoreForMenu", PlaceScoreForMenu)

// Sets the rank name
function LeaderBoardRankName(data)
	local GetPlayerID = data:ReadString()
	local GetTotalRank = data:ReadString()
	if player.GetByID(GetPlayerID):IsValid() then
	player.GetByID(GetPlayerID):SetPData("MyTDMRank", GetTotalRank)
	end
end
usermessage.Hook("LeaderBoardRankName", LeaderBoardRankName)


-- Everything ABOVE this should NEVER be changed, ever.
-- Everything ABOVE this should NEVER be changed, ever.
-- Everything ABOVE this should NEVER be changed, ever.


// Who killed me?
function TDM_Who_Killed_Me(data)
	local KillerName = data:ReadString()
	local KillerColor = data:ReadShort()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You have been killed by ',team.GetColor(KillerColor),KillerName, Color(255,255,255,255),'!')
end
usermessage.Hook("TDM_Who_Killed_Me", TDM_Who_Killed_Me)


// First Blood
function TDM_Player_IS_FK(data)
	surface.PlaySound( "TDM/firstblood.mp3" )
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' First Blood!')
end
usermessage.Hook("TDM_Player_IS_FK", TDM_Player_IS_FK)

// Level Up
function TDMGetNewRankName(data)
	local NewRank = data:ReadString()
	surface.PlaySound( "TDM/levelup.mp3" )
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' Congratulations, you have been promoted to:')
	chat.AddText(Color(255,255,255,255), '         - ',NewRank)
end
usermessage.Hook("TDMGetNewRankName", TDMGetNewRankName)


// Timer Gets turned on or off
function TDM_Changed_Timer(data)
	local TimerName = data:ReadString()
	local TimerColor = data:ReadShort()
	local TimerPos = data:ReadString()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255)," Administrator ",team.GetColor(TimerColor),TimerName,Color(255,255,255,255)," has turned the countdown timer ", Color(255,0,0,255),TimerPos)
end
usermessage.Hook("TDM_Changed_Timer", TDM_Changed_Timer)


// Double Kill
function TDM_Player_IS_DK(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' Double Kill!')
	surface.PlaySound( "TDM/doublekill.mp3" )
end
usermessage.Hook("TDM_Player_IS_DK", TDM_Player_IS_DK)


// Triple Kill
function TDM_Player_IS_TK(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' Triple Kill!')
	surface.PlaySound( "TDM/triplekill.mp3" )
end
usermessage.Hook("TDM_Player_IS_TK", TDM_Player_IS_TK)


// Killing Spree
function TDM_Player_IS_KS(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' Killing Spree!')
	surface.PlaySound( "TDM/killingspree.mp3" )
end
usermessage.Hook("TDM_Player_IS_KS", TDM_Player_IS_KS)


// Killtacular
function TDM_Player_IS_KC(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' Kill-Fucking-Tacular!')
	surface.PlaySound( "TDM/killtacular.mp3" )
end
usermessage.Hook("TDM_Player_IS_KC", TDM_Player_IS_KC)


// Who team killed me?
function TDM_Who_Team_Killed_Me(data)
	local KillerName = data:ReadString()
	local KillerColor = data:ReadShort()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You have been team killed by ',team.GetColor(KillerColor),KillerName, Color(255,255,255,255),'!')
end
usermessage.Hook("TDM_Who_Team_Killed_Me", TDM_Who_Team_Killed_Me)


// Killed Self
function TDM_Killed_Self(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You have killed yourself!')
	end
usermessage.Hook("TDM_Killed_Self", TDM_Killed_Self)


// Who did I kill?
function TDM_Who_Did_I_Kill(data)
	local PlayerName = data:ReadString()
	local PlayerColor = data:ReadShort()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You killed ',team.GetColor(PlayerColor),PlayerName, Color(255,255,255,255),'!')
end
usermessage.Hook("TDM_Who_Did_I_Kill", TDM_Who_Did_I_Kill)


// Who did I team kill?
function TDM_Who_Did_I_Team_Kill(data)
	local PlayerName = data:ReadString()
	local PlayerColor = data:ReadShort()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You team killed ',team.GetColor(PlayerColor),PlayerName, Color(255,255,255,255),'!')
end
usermessage.Hook("TDM_Who_Did_I_Team_Kill", TDM_Who_Did_I_Team_Kill)


// I am alive, so I can not switch teams!
function TDM_Alive_Cant_Switch(data)
	local TeamName = data:ReadString()
	local TeamColor = data:ReadShort()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You will be switched to team ', team.GetColor(TeamColor), TeamName, Color(255,255,255,255), ' when you respawn!')
end
usermessage.Hook("TDM_Alive_Cant_Switch", TDM_Alive_Cant_Switch)


// Can not kill to switch teams faster, sorry!
function TDM_Can_Kill_Self(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' Sorry, but you can not kill yourself!')
end
usermessage.Hook("TDM_Can_Kill_Self", TDM_Can_Kill_Self)


// Game has been won!
function TDM_Game_Won(data)
	local MVPName = data:ReadString()
	local TeamName = data:ReadShort()
	local MVPFrags = data:ReadString()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),'] ',Color(255,255,255,255),team.GetColor(TeamName),team.GetName(TeamName),Color(255,255,255,255)," team has won the game. ",team.GetColor(TeamName),MVPName,Color(255,255,255,255)," being the MVP, having ",Color(255,0,0,255), MVPFrags,Color(255,255,255,255)," kill(s)!" )
	surface.PlaySound( "TDM/team_win.mp3" )
end
usermessage.Hook("TDM_Game_Won", TDM_Game_Won)


// Not and Admin or Administrator
function TDM_Not_Admin(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' Sorry, but you are not an administrator!')
end
usermessage.Hook("TDM_Not_Admin", TDM_Not_Admin)


// Goal is not a number
function TDM_Goal_Not_Number(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' The number you entered is not a number.',Color(255,0,0,255),' Please use a number!')
end
usermessage.Hook("TDM_Goal_Not_Number", TDM_Goal_Not_Number)


// Timer is not a number
function TDM_Timer_Not_Number(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' The number you entered is not a number.',Color(255,0,0,255),' Please use a number!')
end
usermessage.Hook("TDM_Timer_Not_Number", TDM_Timer_Not_Number)


// Changing Score Limit
function TDM_Changed_Score_Limit(data)
	local PlayerName = data:ReadString()
	local TeamName = data:ReadShort()
	local ScoreChange = data:ReadString()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255)," Administrator ",team.GetColor(TeamName),PlayerName,Color(255,255,255,255)," has changed the score limit to ",Color(255,0,0,255),ScoreChange)
end
usermessage.Hook("TDM_Changed_Score_Limit", TDM_Changed_Score_Limit)

// Changing Timer Limit
function TDM_Changed_Timer_Limit(data)
	local PlayerName = data:ReadString()
	local TeamName = data:ReadShort()
	local ScoreChange = data:ReadString()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255)," Administrator ",team.GetColor(TeamName),PlayerName,Color(255,255,255,255)," has changed the time limit to ",Color(255,0,0,255),ScoreChange,Color(255,255,255,255), " minutes.")
end
usermessage.Hook("TDM_Changed_Timer_Limit", TDM_Changed_Timer_Limit)


// Friendly Fire On/Off Warning
function TDM_Changed_Friendly_Fire(data)
	local PlayerName = data:ReadString()
	local TeamName = data:ReadShort()
	local FriendlyFireChange = data:ReadString()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255)," Administrator ",team.GetColor(TeamName),PlayerName,Color(255,255,255,255)," has turned friendly fire ", Color(255,0,0,255),FriendlyFireChange)
end
usermessage.Hook("TDM_Changed_Friendly_Fire", TDM_Changed_Friendly_Fire)


// Armor On/Off Warning
function TDM_Changed_Armor(data)
	local PlayerName = data:ReadString()
	local TeamName = data:ReadShort()
	local ArmorChange = data:ReadString()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255)," Administrator ",team.GetColor(TeamName),PlayerName,Color(255,255,255,255)," has turned armor ", Color(255,0,0,255),ArmorChange)
end
usermessage.Hook("TDM_Changed_Armor", TDM_Changed_Armor)


// Goal has equaled Zero
function TDM_Goal_Is_Zero(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' The number you entered is zero or is below zero!',Color(255,0,0,255),' Please use a different number!')
end
usermessage.Hook("TDM_Goal_Is_Zero", TDM_Goal_Is_Zero)

// Timer has equaled Zero
function TDM_Timer_Is_Zero(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' The number you entered is zero or is below zero!',Color(255,0,0,255),' Please use a different number!')
end
usermessage.Hook("TDM_Timer_Is_Zero", TDM_Timer_Is_Zero)

// Timer has a decimal in it
function TDM_Timer_Has_Decimal(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' The number you entered has a decimal point in it!',Color(255,0,0,255),' Please use a whole number!')
end
usermessage.Hook("TDM_Timer_Has_Decimal", TDM_Timer_Has_Decimal)

// Goal has a decimal in it
function TDM_Goal_Has_Decimal(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' The number you entered has a decimal point in it!',Color(255,0,0,255),' Please use a whole number!')
end
usermessage.Hook("TDM_Goal_Has_Decimal", TDM_Goal_Has_Decimal)


// Welcome message
function TDM_Welcome_To_Server(data)
	local PlayerName = data:ReadString()
	local TeamName = data:ReadShort()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' Welcome, ',team.GetColor(TeamName),PlayerName,Color(255,255,255,255),' to ',Color(255,0,0,255),GetHostName(),Color(255,255,255,255),'!')
	surface.PlaySound( "TDM/SM.mp3" )
	surface.PlaySound( "TDM/joinserver.mp3" )
end
usermessage.Hook("TDM_Welcome_To_Server", TDM_Welcome_To_Server)


// TDM HELP LOOK AT CONSOLE MESSAGE
function TDM_HELP_CONSOLE(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' Please look at console to see the list of help options', Color(255,255,255,255),'!')
end
usermessage.Hook("TDM_HELP_CONSOLE", TDM_HELP_CONSOLE)


// TDM POINTS ARE TOO LOW TO BUY WEAPONS
function TDMPOINTSARETOOLOW(data)
local CurrentPoints = data:ReadString()
local WeaponPoints = data:ReadString()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You only have ',Color(255,0,0,255),CurrentPoints,Color(255,255,255,255),' points')
	chat.AddText(Color(255,255,255,255),'The weapon you want to buy cost ',Color(255,0,0,255),WeaponPoints, Color(255,255,255,255),' points !')
end
usermessage.Hook("TDMPOINTSARETOOLOW", TDMPOINTSARETOOLOW)


// TDM POINTS HAVE BEEN SPENT
function TDMPOINTWEAPON(data)
local WeaponBought = data:ReadString()
local WeaponPoints = data:ReadString()
local NewPoints = data:ReadString()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You have bought a ',Color(255,0,0,255),WeaponBought,Color(255,255,255,255),' for ',Color(255,0,0,255),WeaponPoints,Color(255,255,255,255),' points!')
	chat.AddText(Color(255,255,255,255),'You now have ',Color(255,0,0,255),NewPoints, Color(255,255,255,255),' points !')
end
usermessage.Hook("TDMPOINTWEAPON", TDMPOINTWEAPON)


// TDM POINTS HAVE BEEN SPENT; PLAY SONG
function TDMPOINTOTHER(data)
local PlayerName = data:ReadString()
local TeamName = data:ReadShort()
local OtherName = data:ReadString()
local OtherPoints = data:ReadString()
local OtherCoreFile = data:ReadString()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),'] ',team.GetColor(TeamName),PlayerName,Color(255,255,255,255),' has bought the song ',Color(255,0,0,255),OtherName,Color(255,255,255,255),' for ',Color(255,0,0,255),OtherPoints,Color(255,255,255,255),' points!')
	chat.AddText(Color(255,255,255,255),'Type ',Color(255,0,0,255),'!stopsong',Color(255,255,255,255),' to stop the song for yourself.')
--surface.PlaySound( OtherCoreFile )
        if LocalPlayer().channel ~= nil && LocalPlayer().channel:IsValid() then
                LocalPlayer().channel:Stop()
        end
        sound.PlayURL(OtherCoreFile,"",function(ch)
                if ch != nil and ch:IsValid() then
                        ch:Play()
                        LocalPlayer().channel = ch
                end
                end)
end
usermessage.Hook("TDMPOINTOTHER", TDMPOINTOTHER)


function stopmysongplease2(data)
local stoppingsong = "You have stopped the song for yourself."
        if LocalPlayer().channel ~= nil && LocalPlayer().channel:IsValid() then
                LocalPlayer().channel:Stop()
        end
	chat.AddText(Color(0,0,200),stoppingsong)
end

usermessage.Hook("stopmysongplease2",stopmysongplease2)


// TDM POINTS HAVE BEEN SPENT; PLAY SONG2
function TDMPOINTOTHER2(data)
local NewPoints = data:ReadString()
	chat.AddText(Color(255,255,255,255),'You now have ',Color(255,0,0,255),NewPoints, Color(255,255,255,255),' points !')
end
usermessage.Hook("TDMPOINTOTHER2", TDMPOINTOTHER2)


// TDM MISSING MONEY AMOUNT
function TDM_Give_Points_Amount_Missing(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You did not enter a money amount, please enter amount!')
end
usermessage.Hook("TDM_Give_Points_Amount_Missing", TDM_Give_Points_Amount_Missing)


// TDM MISSING MONEY GIVE PLAYER ID
function TDM_Give_Points_ID_Missing(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You did not select a name, please select name!')
end
usermessage.Hook("TDM_Give_Points_ID_Missing", TDM_Give_Points_ID_Missing)


// TDM MONEY GIVE PLAYER SUCCESSFUL
function TDM_Give_Points_Successfully(data)
--local AdminName = data:ReadString()
local PlayerName = data:ReadString()
local MoneySet = data:ReadString()
local AdminTeam = data:ReadShort()
local PlayerTeam = data:ReadShort()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),'] ', team.GetColor(AdminTeam), "You", Color(255,255,255,255),' gave ',team.GetColor(PlayerTeam),PlayerName,', ',Color(0,255,0,255),MoneySet,Color(255,255,255,255), ' points!')
end
usermessage.Hook("TDM_Give_Points_Successfully", TDM_Give_Points_Successfully)


// TDM MISSING MONEY AMOUNT
function TDM_Set_Points_Amount_Missing(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You did not enter a money amount, please enter amount!')
end
usermessage.Hook("TDM_Set_Points_Amount_Missing", TDM_Set_Points_Amount_Missing)


// TDM MISSING MONEY GIVE PLAYER ID
function TDM_Set_Points_ID_Missing(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You did not select a name, please select name!')
end
usermessage.Hook("TDM_Set_Points_ID_Missing", TDM_Set_Points_ID_Missing)


// TDM MONEY GIVE PLAYER SUCCESSFUL
function TDM_Set_Points_Successfully(data)
local AdminName = data:ReadString()
local PlayerName = data:ReadString()
local MoneySet = data:ReadString()
local AdminTeam = data:ReadShort()
local PlayerTeam = data:ReadShort()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),'] ', team.GetColor(AdminTeam), AdminName, Color(255,255,255,255),' set ',team.GetColor(PlayerTeam),PlayerName,"'s",Color(255,255,255,255)," points to ",Color(0,255,0,255),MoneySet)
end
usermessage.Hook("TDM_Set_Points_Successfully", TDM_Set_Points_Successfully)

// TDM MONEY GIVE PLAYER SUCCESSFUL
function TDM_PGive_Points_Successfully(data)
local AdminName = data:ReadString()
--local PlayerName = data:ReadString()
local MoneySet = data:ReadString()
local AdminTeam = data:ReadShort()
local PlayerTeam = data:ReadShort()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),'] ', team.GetColor(PlayerTeam), "You", Color(255,255,255,255),' received ',Color(0,255,0,255),MoneySet,Color(255,255,255,255),' points from ',team.GetColor(AdminTeam),AdminName,'!')
end
usermessage.Hook("TDM_PGive_Points_Successfully", TDM_PGive_Points_Successfully)

// TDM MONEY GIVE PLAYER SUCCESSFUL
function TDM_Give_Points_Not_Successfully(data)
local PlayerPoints = data:ReadString()
local PPlayerPoints = data:ReadString()
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),'] ',' You only have ', Color(255,0,0,255),PlayerPoints,Color(255,255,255,255),' points, you can not give ', Color(255,0,0,255),PPlayerPoints,Color(255,255,255,255),' points!')
end
usermessage.Hook("TDM_Give_Points_Not_Successfully", TDM_Give_Points_Not_Successfully)

// TDM GIVE MONEY TO SELF
function TDM_Give_Points_Self(data)
	chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),']',Color(255,255,255,255),' You can not give money to yourself!')
	chat.AddText(Color(255,255,255,255),' - You can set your points if you are an admin.')
end
usermessage.Hook("TDM_Give_Points_Self", TDM_Give_Points_Self)